# coding=utf-8

from framework.db.mysql import BaseDb
from tornado import gen
from lib import log
import md5


class Register(BaseDb):

    @gen.coroutine
    def register(self, username, passwd, schoolid):
        ins_sql = "INSERT INTO tb_user_login(Fuser_name,Fpwd,Ftype,Fschool_id,Fcreate_time) \
                    VALUES(%s,%s,%s,%s,UNIX_TIMESTAMP())"
        # try:
        passwd = md5.md5(passwd).hexdigest()
        ret = yield self.upsert_commit(ins_sql, (username, passwd, '1', schoolid))
        # except Exception, e:
        #     raise e
        raise gen.Return(ret)
